package com.bingyuan.aipassproject.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bingyuan.aipassproject.R;
import com.bingyuan.aipassproject.entity.EventMsgResponse;
import com.bingyuan.aipassproject.utils.ShareUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

public class MultipleItemAdapter extends BaseMultiItemQuickAdapter<EventMsgResponse, BaseViewHolder> {

    private Context context;

    public MultipleItemAdapter(Context context, List data) {
        super(data);
        this.context = context;
        //必须绑定type和layout的关系
        addItemType(1, R.layout.item_room_record_type_send);
        addItemType(2, R.layout.item_room_record_type_rob);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, EventMsgResponse eventMsgResponse) {
        baseViewHolder.setIsRecyclable(false);
        if (baseViewHolder.getItemViewType() == 1) {
            TextView tvMine = baseViewHolder.getView(R.id.tvMine);
            ImageView ivIcon = baseViewHolder.getView(R.id.ivSendIcon);
            String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
            if (eventMsgResponse.getUser_id() == Integer.valueOf(userId)){
                tvMine.setVisibility(View.VISIBLE);
            }
            //头像
            if (eventMsgResponse.getFace()==null||eventMsgResponse.getFace().equals("false")) {
                Glide.with(context).load(R.drawable.icon_csc).into(ivIcon);
            } else {
                Glide.with(context).load(eventMsgResponse.getFace())
                        .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                        .into(ivIcon);
            }
            //用户名
            baseViewHolder.setText(R.id.tvUserName, eventMsgResponse.getNickname());
            //时间
            baseViewHolder.setText(R.id.tvDate, eventMsgResponse.getTime());

            //标题
            baseViewHolder.setText(R.id.tvTitle, eventMsgResponse.getStake_score() + "金币" + "(" + eventMsgResponse.getNum() + "包)");

            //雷数目
            if (eventMsgResponse.getSelect().size() == 1) {
                baseViewHolder.setText(R.id.tvSendType, "一雷");
                baseViewHolder.setText(R.id.tvSelectNum, "雷号：" + eventMsgResponse.getSelect().get(0));
            } else if (eventMsgResponse.getSelect().size() == 2) {
                baseViewHolder.setText(R.id.tvSendType, "多雷");
                baseViewHolder.setText(R.id.tvSelectNum, "雷号：" + eventMsgResponse.getSelect().get(0) + "," + eventMsgResponse.getSelect().get(1));
            }
        }else if (baseViewHolder.getItemViewType()==2){
            if (eventMsgResponse.getClaim_score()!=0){
                if (eventMsgResponse.getSelect().size()==1){
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id()==Integer.valueOf(userId)){
                        baseViewHolder.setText(R.id.tvContent,"您参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+")】,"+"您意外损失"+eventMsgResponse.getClaim_score()+"金币");
                    }else {
                        baseViewHolder.setText(R.id.tvContent,eventMsgResponse.getNickname()+"参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+")】,"+"意外损失"+eventMsgResponse.getClaim_score()+"金币");
                    }
                }else if (eventMsgResponse.getSelect().size()==2){
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id()==Integer.valueOf(userId)){
                        baseViewHolder.setText(R.id.tvContent,"您参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+","+eventMsgResponse.getSelect().get(1)+")】,"+"您意外损失"+eventMsgResponse.getClaim_score()+"金币");
                    }else {
                        baseViewHolder.setText(R.id.tvContent,eventMsgResponse.getNickname()+"参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+","+eventMsgResponse.getSelect().get(1)+")】,"+"意外损失"+eventMsgResponse.getClaim_score()+"金币");
                    }
                }
            }else {
                if (eventMsgResponse.getSelect().size()==1){
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id()==Integer.valueOf(userId)){
                        baseViewHolder.setText(R.id.tvContent,"您参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+")】,");
                    }else {
                        baseViewHolder.setText(R.id.tvContent,eventMsgResponse.getNickname()+"参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+")】,");
                    }
                }else if (eventMsgResponse.getSelect().size()==2){
                    String userId = ShareUtil.getInstance().get(ShareUtil.USERID);
                    if (eventMsgResponse.getUser_id()==Integer.valueOf(userId)){
                        baseViewHolder.setText(R.id.tvContent,"您参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+","+eventMsgResponse.getSelect().get(1)+")】,");
                    }else {
                        baseViewHolder.setText(R.id.tvContent,eventMsgResponse.getNickname()+"参与砸蛋，获得 "+eventMsgResponse.getRob_score() +" 金币 【雷 号("+eventMsgResponse.getSelect().get(0)+","+eventMsgResponse.getSelect().get(1)+")】,");
                    }
                }
            }
        }
    }
}
